<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3" xmlns:head="http://www.w3.org/1999/html">
<head th:include="public/public_css::public_css ('配置订单管理')"/>

<body style="background-color: #f2f2f2;">
<div id="title" class="layui-input">
    <input type="text" class="layui-input" readonly value="配置订单管理"/><input style="position: absolute;right: 0;" th:value="${mc}"  class="layui-input" readonly/>
</div>
<div class="layui-fluid larry-wrapper">
    <div class="layui-card">
        <div class="layui-row layui-col-space30">
            <div class="layui-col-xs24">
                <form class="layui-form layui-card-header  layui-card-header-auto" id="searchForm">
                    <div class="layui-inline">
                        <label class="layui-form-label">订单分类</label>
                        <div class="layui-input-inline" >
                            <select name="fl" lay-filter="filter" id="fl">
                                <option value="">全部</option>
                                <option value="0">入库单</option>
                                <option value="1">出库单</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">订单类型</label>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" id="ddlx" name="ddlx" placeholder="订单类型"/>
                        </div>
                    </div>
                    <input type="hidden" class="layui-input" th:value="${id}" id="sshzid" name="sshzid"/>
                    <div class="layui-inline inline-search-btn">
                        <a class="layui-btn layui-btn-normal" data-type="reload">查询</a>
                    </div>
                    <div class="layui-inline inline-reset-btn">
                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                    </div>
                </form>
                <!--顶部按钮展示区域 【 tpl-button 】 -->
                <div class="group-button tpl-button" id="toolbar"></div>
                <!--  <div class="group-button" id="toolbar">

                      <a class="layui-btn layui-btn-sm layui-btn-normal add-btn">
                          <i class="layui-icon">&#x1005;</i> 新增
                      </a>
                      <a class="layui-btn layui-btn-sm layui-btn-normal edit-btn">
                          <i class="layui-icon">&#x1005;</i> 修改
                      </a>
                  </div>-->
                <!--列表-->
                <section class="panel panel-padding layui-card-body">
                    <div class="pro">
                        <table id="table" class="table text-nowrap"></table>
                    </div>
                </section>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn" jq-filter="submit" lay-submit="" lay-filter="addOwerdd">立即提交</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

</body>
<div th:include="public/public_js::public_js"></div>
<div th:include="public/public_btn::public_btn"></div>
<style type="text/css">
    .moreBtn {
        width: 50px;
        height: 20px;
        text-align: center;
        color: #fff;
        line-height: 20px;
        background-color: #eee;
        position: relative;
        margin: 0 auto;
        cursor: pointer;
    }

    .moreBtn:before {
        content: '';
        display: block;
        width: 35px;
        height: 20px;
        position: absolute;
        transform: skewX(30deg);
        background: #eee;
        border-top-left-radius: 8px;
        left: -20px;
        top: 0;
    }

    .moreBtn:after {
        content: '';
        display: block;
        width: 35px;
        height: 20px;
        position: absolute;
        transform: skewX(-30deg);
        background: #eee;
        border-top-right-radius: 8px;
        top: 0;
        right: -20px;
    }
    #title{
        height: 4rem;
        border-radius: 5px;
    }
    #title input{
        display: inline-block;
        width: 20rem;
        border: 0;
        background-color: white;
    }
</style>
<script th:inline="javascript">
    var functions = [[${functions}]];
    layui.use(['list', 'layer', 'zzpUtils', 'jquery', 'laydate','tablebutton'], function () {
        var zzpUtils = layui.zzpUtils,
            $ = layui.jquery,
            laydate = layui.laydate,
            tablebtn = layui.tablebutton;
        var form = layui.form;
        var $table;

        var ids=[];
        var $table = zzpUtils.table({
            elem: '#table',
            isApi: true,
            pagination: true,
            url: '/wmsOwner/getOrderTypeByHzId/'+$('#sshzid').val(),
            columns: [{
                field: '',
                checkbox: true,
                formatter: function (i,row) {            // 每次加载 checkbox 时判断当前 row 的 id 是否已经存在全局 Set() 里
                    if ($.inArray(row.id, ids) != -1) {// 因为 判断数组里有没有这个 id
                        return {
                            checked: true               // 存在则选中
                        }
                    }
                }
            },{
                field: 'mc',
                title: '货主名称',
            },{
                field: 'ddlx',
                title: '订单类型'
            },{
                field: 'show_fl',
                title: '订单分类'
            }],
            queryParams: function () {//查询条件
                return  zzpUtils.getFormJson($("#searchForm"));
            },
            detailFormatter: function (index, row) {
                return "这里就没有确定过11";
            },
            //部分选中
            onCheck:function(row,index){
                btn_cha(row.id);
            },
            //部分反选
            onUncheck:function(row,index){
                btn_cha(row.id);
            },
            //全部选中
            onCheckAll:function(rows,index){
                $.each(rows, function (i, item) {
                    btn_chaAll(item.id);
                });
            },
            //全部反选
            onUncheckAll:function(rows,index){
                $.each(rows, function (i, item) {
                    btn_cha(item.id);
                });

            }
        });

        //除全部选中外的另外三个(部分选中,部分反选,全部反选)
        function btn_cha(id){
            if(ids.indexOf(id)>-1){
                var index = ids.indexOf(id);
                if (index > -1) {
                    ids.splice(index, 1);
                }
            }else{
                ids.push(id);
            }
        }
        //全部选中
        function btn_chaAll(id){
            if(ids.indexOf(id)>-1){
                var index = ids.indexOf(id);
                if (index > -1) {
                }
            }else{
                ids.push(id);
            }
        }

        //查询已勾选的货主订单类型
        $(function () {
            $.ajax({
                url: '/zxsswms/wmsOwner/getOrderTypeIds/'+$('#sshzid').val(),
                type: 'GET',
                dataType: 'json',
                contentType: "application/json",
                async: false,
                success: function(data){
                    ids = data;
                }
            })
        })
        $(".inline-search-btn").on('click',function () {
            zzpUtils.refreshTable("#table");
        })
        //保存货主订单类型的ids
        form.on("submit(addOwerdd)",function(data){
            var list =[];
            $.each(ids, function (i, item) {
                list.push(
                    item
                );
            });
            var data = {
                "ids":list,
                "sshzid":$('#sshzid').val()
            };
            zzpUtils.confirm("是否确定保存",function(index){
                zzpUtils.action({
                    url:"/wmsOwner/editOrderType",
                    data:JSON.stringify(data),
                    success:function (data) {
                        setTimeout(function(){
                            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            parent.layer.close(index); //再执行关闭
                            top.layer.msg(data.title);
                        },500);
                    },error: function (xhr, textStatus) {
                        console.log(textStatus);
                        console.log(xhr);
                    }
                })
            })

            return false;
        });
    });

</script>
</html>